from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-16 14:02:14.596829
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 16, Nov, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9618
Nobs: 842.000 HQIC: -51.2740
Log likelihood: 11005.3 FPE: 4.44368e-23
AIC: -51.4680 Det(Omega_mle): 3.99572e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299075 0.050608 5.910 0.000
L1.Burgenland 0.109775 0.034775 3.157 0.002
L1.Kärnten -0.106128 0.018527 -5.728 0.000
L1.Niederösterreich 0.210993 0.072732 2.901 0.004
L1.Oberösterreich 0.101190 0.069176 1.463 0.144
L1.Salzburg 0.252113 0.036885 6.835 0.000
L1.Steiermark 0.037114 0.048367 0.767 0.443
L1.Tirol 0.107403 0.039198 2.740 0.006
L1.Vorarlberg -0.060394 0.033796 -1.787 0.074
L1.Wien 0.053022 0.061901 0.857 0.392
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067343 0.104387 0.645 0.519
L1.Burgenland -0.030441 0.071728 -0.424 0.671
L1.Kärnten 0.047589 0.038215 1.245 0.213
L1.Niederösterreich -0.173337 0.150020 -1.155 0.248
L1.Oberösterreich 0.379418 0.142685 2.659 0.008
L1.Salzburg 0.288514 0.076079 3.792 0.000
L1.Steiermark 0.107725 0.099763 1.080 0.280
L1.Tirol 0.315714 0.080851 3.905 0.000
L1.Vorarlberg 0.022920 0.069709 0.329 0.742
L1.Wien -0.019110 0.127679 -0.150 0.881
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197209 0.026200 7.527 0.000
L1.Burgenland 0.092494 0.018003 5.138 0.000
L1.Kärnten -0.008737 0.009592 -0.911 0.362
L1.Niederösterreich 0.268220 0.037653 7.123 0.000
L1.Oberösterreich 0.115405 0.035812 3.222 0.001
L1.Salzburg 0.052704 0.019095 2.760 0.006
L1.Steiermark 0.016486 0.025039 0.658 0.510
L1.Tirol 0.098296 0.020293 4.844 0.000
L1.Vorarlberg 0.056087 0.017496 3.206 0.001
L1.Wien 0.112851 0.032046 3.522 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105204 0.026846 3.919 0.000
L1.Burgenland 0.047160 0.018447 2.557 0.011
L1.Kärnten -0.017187 0.009828 -1.749 0.080
L1.Niederösterreich 0.197290 0.038582 5.114 0.000
L1.Oberösterreich 0.280266 0.036696 7.638 0.000
L1.Salzburg 0.120833 0.019566 6.176 0.000
L1.Steiermark 0.101538 0.025657 3.958 0.000
L1.Tirol 0.123187 0.020793 5.924 0.000
L1.Vorarlberg 0.069022 0.017928 3.850 0.000
L1.Wien -0.028104 0.032836 -0.856 0.392
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130053 0.048642 2.674 0.008
L1.Burgenland -0.049512 0.033424 -1.481 0.139
L1.Kärnten -0.039607 0.017807 -2.224 0.026
L1.Niederösterreich 0.166385 0.069906 2.380 0.017
L1.Oberösterreich 0.139277 0.066489 2.095 0.036
L1.Salzburg 0.285310 0.035452 8.048 0.000
L1.Steiermark 0.032899 0.046488 0.708 0.479
L1.Tirol 0.163325 0.037675 4.335 0.000
L1.Vorarlberg 0.103889 0.032483 3.198 0.001
L1.Wien 0.069691 0.059496 1.171 0.241
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058976 0.038528 1.531 0.126
L1.Burgenland 0.042616 0.026474 1.610 0.107
L1.Kärnten 0.049812 0.014105 3.532 0.000
L1.Niederösterreich 0.228143 0.055370 4.120 0.000
L1.Oberösterreich 0.272479 0.052663 5.174 0.000
L1.Salzburg 0.058405 0.028080 2.080 0.038
L1.Steiermark -0.006995 0.036821 -0.190 0.849
L1.Tirol 0.156234 0.029841 5.236 0.000
L1.Vorarlberg 0.067837 0.025729 2.637 0.008
L1.Wien 0.072997 0.047125 1.549 0.121
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184827 0.046121 4.007 0.000
L1.Burgenland -0.004464 0.031692 -0.141 0.888
L1.Kärnten -0.060970 0.016885 -3.611 0.000
L1.Niederösterreich -0.086759 0.066283 -1.309 0.191
L1.Oberösterreich 0.192186 0.063043 3.048 0.002
L1.Salzburg 0.059650 0.033614 1.775 0.076
L1.Steiermark 0.225726 0.044078 5.121 0.000
L1.Tirol 0.494886 0.035723 13.854 0.000
L1.Vorarlberg 0.047631 0.030800 1.546 0.122
L1.Wien -0.050700 0.056413 -0.899 0.369
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159047 0.052525 3.028 0.002
L1.Burgenland -0.009274 0.036092 -0.257 0.797
L1.Kärnten 0.064722 0.019229 3.366 0.001
L1.Niederösterreich 0.202984 0.075487 2.689 0.007
L1.Oberösterreich -0.067991 0.071796 -0.947 0.344
L1.Salzburg 0.223324 0.038282 5.834 0.000
L1.Steiermark 0.113323 0.050199 2.257 0.024
L1.Tirol 0.084365 0.040683 2.074 0.038
L1.Vorarlberg 0.122156 0.035076 3.483 0.000
L1.Wien 0.109006 0.064246 1.697 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357249 0.030928 11.551 0.000
L1.Burgenland 0.008891 0.021252 0.418 0.676
L1.Kärnten -0.024574 0.011322 -2.170 0.030
L1.Niederösterreich 0.228895 0.044448 5.150 0.000
L1.Oberösterreich 0.158246 0.042275 3.743 0.000
L1.Salzburg 0.053929 0.022541 2.392 0.017
L1.Steiermark -0.018590 0.029558 -0.629 0.529
L1.Tirol 0.117166 0.023955 4.891 0.000
L1.Vorarlberg 0.071822 0.020654 3.477 0.001
L1.Wien 0.048170 0.037829 1.273 0.203
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043754 0.160946 0.192414 0.165880 0.131715 0.124123 0.069998 0.230339
Kärnten 0.043754 1.000000 0.001807 0.131796 0.045204 0.099476 0.427871 -0.050761 0.101913
Niederösterreich 0.160946 0.001807 1.000000 0.345770 0.166621 0.311508 0.127591 0.192003 0.340574
Oberösterreich 0.192414 0.131796 0.345770 1.000000 0.235981 0.341084 0.178100 0.180006 0.274907
Salzburg 0.165880 0.045204 0.166621 0.235981 1.000000 0.153309 0.145131 0.152695 0.140917
Steiermark 0.131715 0.099476 0.311508 0.341084 0.153309 1.000000 0.163334 0.148817 0.092636
Tirol 0.124123 0.427871 0.127591 0.178100 0.145131 0.163334 1.000000 0.121982 0.164250
Vorarlberg 0.069998 -0.050761 0.192003 0.180006 0.152695 0.148817 0.121982 1.000000 0.018639
Wien 0.230339 0.101913 0.340574 0.274907 0.140917 0.092636 0.164250 0.018639 1.000000